package model

import (
	"gorm.io/gorm"
)

type Video struct {
	gorm.Model
	Title        string  `json:"title"`
	Introduce    string  `json:"introduce"`
	CoverUrl     string  `json:"coverUrl"`
	Category     string  `json:"category"`
	Types        string  `json:"types"`
	Actor        string  `json:"actor"`
	Year         string  `json:"year"`
	Address      string  `json:"address"`
	PlayCount    int64   `gorm:"default:0" json:"playCount"`
	LikeCount    int64   `gorm:"default:0" json:"likeCount"`
	CollectCount int64   `gorm:"default:0" json:"collectCount"`
	CommentCount int64   `gorm:"default:0" json:"commentCount"`
	Hot          int64   `gorm:"default:0" json:"hot"`
	Status       int64   `gorm:"default:0" json:"status"`
	Score        float64 `gorm:"default:0" json:"score"`
	Reason       string  `json:"reason"`
}

type Episode struct {
	gorm.Model
	VideoId    int64  ` json:"videoId"`
	Title      string `json:"title"`
	EpisodeNum int64  `json:"episodeNum"`
	Duration   int64  `json:"duration"`
	FileUrl    string `json:"fileUrl"`
}

func (v *Video) VideoTypes(db *gorm.DB) *Episode {
	if v.Types == "电影" {
		return &Episode{
			Title: v.Title,
		}
	}

	if v.Types == "电视剧" {
		return &Episode{
			Title: v.Title,
		}
	}

	return &Episode{}
}

type PlayLog struct {
	gorm.Model
	UserId   int64 `json:"userId"`
	VideoId  int64 `json:"videoId"`
	Duration int64 `json:"duration"`
}

func (v *Video) HotCount(PlayCount, LikeCount, CollectCount, CommentCount int64) float64 {
	hot := float64(PlayCount)*0.6 + float64(LikeCount)*0.2 + float64(CollectCount)*0.1 + float64(CommentCount)*0.1
	return hot
}
